//
// Decompiled by Jadx - 729ms
//
package fn;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.text.TextUtils;
import android.view.View;
import androidx.activity.b;
import com.google.gson.Gson;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import fo.c;
import gc.af;
import ge.o;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import me.plusne.common.Json.JsonHookStatic;
import org.luckypray.dexkit.query.matchers.MethodMatcher;
import org.luckypray.dexkit.result.ClassData;
import org.luckypray.dexkit.result.ClassDataList;
import org.luckypray.dexkit.result.MethodData;
import r.f;
import r.g;

public class j {
    public static final HashMap<String, Class<?>> p = new HashMap<>();

    public static Object aa(Object obj, String str) {
        if (str == null) {
            bj();
            bi(b.i("Call失败:", str, " 找不到此类"));
            return null;
        }
        String aj = aj(str.trim());
        if (aj == null) {
            bj();
            bi(b.i("Call失败:", aj, " 找不到此类1"));
            return null;
        }
        try {
            return XposedHelpers.callMethod(obj, aj.trim(), new Object[0]);
        } catch (XposedHelpers.InvocationTargetError | NoSuchMethodError | NullPointerException e) {
            e.printStackTrace();
            bi(e);
            bj();
            return null;
        }
    }

    public static Object ab(Object obj, String str, Object... objArr) {
        if (str == null) {
            bj();
            bi(b.i("Call失败:", str, " 找不到此methodName"));
            return null;
        }
        String aj = aj(str.trim());
        if (aj == null) {
            bj();
            bi(b.i("Call失败:", aj, " 找不到此类methodName_1"));
            return null;
        }
        try {
            return XposedHelpers.callMethod(obj, aj, objArr);
        } catch (XposedHelpers.InvocationTargetError | NoSuchMethodError | NullPointerException e) {
            bi(e);
            bj();
            e.printStackTrace();
            return null;
        }
    }

    public static void ac(int i, View view) {
        View view2;
        if (i == 0 || view == null || (view2 = (View) ab(ax(i, view), "getChildAt", 0)) == null) {
            return;
        }
        view2.callOnClick();
    }

    public static Object ad(Class<?> cls, String str, Object... objArr) {
        if (str == null) {
            bj();
            bi(b.i("Call失败:", str, " 找不到此类"));
            return null;
        }
        String aj = aj(str.trim());
        if (aj == null) {
            bj();
            bi(b.i("Call失败:", aj, " 找不到此类1"));
            return null;
        }
        try {
            return XposedHelpers.callStaticMethod(cls, aj, objArr);
        } catch (NoSuchFieldError | NoSuchMethodError | NullPointerException | XposedHelpers.InvocationTargetError e) {
            e.printStackTrace();
            bi(e);
            bj();
            return null;
        }
    }

    public static boolean ae(String str) {
        JsonHookStatic jsonHookStatic = y.by;
        if (jsonHookStatic.getHookData() == null || jsonHookStatic.isExpire() || !bg()) {
            return false;
        }
        return b.h(str.trim(), false);
    }

    public static int af(String str) {
        if (y.by.isLongClick() || !ae("View_ALL")) {
            return 255;
        }
        return ae("View_Unified_Check") ? y.cd(255, "View_Unified") : y.cd(255, str);
    }

    public static int ag(String str) {
        int i;
        try {
            i = Integer.parseInt(str);
        } catch (NumberFormatException unused) {
            i = 255;
        }
        if (y.by.isLongClick() || !ae("View_ALL")) {
            return 255;
        }
        return ae("View_Unified_Check") ? y.cd(255, "View_Unified") : i;
    }

    public static void ah(Object obj) {
        if (obj == null) {
            g.h(y.by.getActivity(), "[复制的内容为空]");
        } else {
            g.h(y.by.getActivity(), new Gson().toJson(obj));
        }
    }

    public static void ai(String str) {
        g.h(y.by.getActivity(), str);
    }

    public static String aj(String str) {
        if (!str.startsWith("@")) {
            return str;
        }
        String cj = y.cj(str.substring(1));
        if (!TextUtils.isEmpty(cj)) {
            return cj;
        }
        bi(str.concat(" 数据解密失败"));
        return null;
    }

    public static Class<?> ak(String str) {
        Class<?> cls;
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        String aj = aj(str);
        HashMap<String, Class<?>> hashMap = p;
        if (aj != null) {
            try {
                cls = hashMap.get(aj.trim());
            } catch (Error e) {
                e.printStackTrace();
                bi(e);
                bj();
                return null;
            }
        } else {
            cls = null;
        }
        if (cls != null || aj == null) {
            return cls;
        }
        Class<?> findClass = XposedHelpers.findClass(aj.trim(), y.by.getClassLoader());
        hashMap.put(aj.trim(), findClass);
        return findClass;
    }

    public static Class<?> al(String str) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        String aj = aj(str);
        try {
            HashMap<String, Class<?>> hashMap = p;
            Class<?> cls = hashMap.get(aj.trim());
            if (cls != null) {
                return cls;
            }
            Class<?> findClassIfExists = XposedHelpers.findClassIfExists(aj.trim(), y.by.getClassLoader());
            hashMap.put(aj.trim(), findClassIfExists);
            return findClassIfExists;
        } catch (XposedHelpers.ClassNotFoundError e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String am(Object obj) {
        Object objectField;
        Object objectField2;
        if (obj == null || (objectField = XposedHelpers.getObjectField(obj, "music")) == null || (objectField2 = XposedHelpers.getObjectField(objectField, "playUrl")) == null) {
            return null;
        }
        String str = (String) aa(objectField2, "getUri");
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        return str;
    }

    public static String an(String str) {
        String str2;
        Object aa;
        Object bk = bk(ak("com.ss.android.ugc.aweme.model.TextExtraStruct"), new Object[0]);
        int cd = y.cd(0, "CommentColor");
        if (cd == 1) {
            JsonHookStatic jsonHookStatic = y.by;
            if (jsonHookStatic.isExpire()) {
                b.r(jsonHookStatic.getActivity(), "未登录,或者未充值");
                return str;
            }
        }
        XposedHelpers.setIntField(bk, "end", str.length());
        XposedHelpers.setIntField(bk, "type", cd);
        try {
            aa = ad(XposedHelpers.findClass("com.ss.android.ugc.aweme.account.AccountProxyService", y.bz), "userService", new Object[0]);
        } catch (XposedHelpers.ClassNotFoundError e) {
            e.printStackTrace();
            Class<?> ak = ak("com.ss.android.ugc.aweme.AccountService");
            if (ak == null) {
                str2 = "";
            } else {
                str2 = ak.getDeclaredMethods()[0].getName();
            }
            aa = aa(ad(ak, str2, new Object[0]), o.cp.getMethodName());
        }
        String str3 = (String) aa(aa, "getCurUserId");
        if (TextUtils.isEmpty(str3)) {
            str3 = "1800000000";
        }
        bn(bk, "atUserType", "");
        bn(bk, "mSecUid", str3);
        JsonHookStatic jsonHookStatic2 = y.by;
        bn(bk, "userId", (String) aa(jsonHookStatic2.getAweme(), "getAuthorUid"));
        if (!jsonHookStatic2.getPre().equals("TK")) {
            bn(bk, "mentionMethod", "button");
        }
        XposedHelpers.setBooleanField(bk, "isClickable", true);
        XposedHelpers.setIntField(bk, "userFollowStatus", 1);
        return new Gson().toJson(bk);
    }

    public static int ao(Object obj) {
        Object objectField = XposedHelpers.getObjectField(obj, "author");
        if (objectField != null) {
            return ((Integer) aa(objectField, "getFollowStatus")).intValue();
        }
        return 0;
    }

    public static String ap() {
        return aq(y.by.getAweme());
    }

    public static String aq(Object obj) {
        if (obj == null) {
            return String.valueOf(System.currentTimeMillis());
        }
        Object objectField = XposedHelpers.getObjectField(obj, "music");
        String as = as(obj, "desc");
        if (objectField == null) {
            return String.valueOf(System.currentTimeMillis());
        }
        String as2 = as(objectField, "musicName");
        if (TextUtils.isEmpty(as2)) {
            return String.valueOf(System.currentTimeMillis());
        }
        return as2.replaceAll("[^\\u4e00-\\u9fa5\\w\\-\\.]", "").trim() + "_" + as.replaceAll("[^\\u4e00-\\u9fa5\\w\\-\\.]", "").trim();
    }

    @SuppressLint({"DiscouragedApi"})
    public static int ar(String str, String str2) {
        String trim = str.trim();
        String trim2 = str2.trim();
        String str3 = null;
        if (TextUtils.isEmpty(null)) {
            str3 = y.by.getLpparam().appInfo.packageName;
        }
        return y.by.getActivity().getResources().getIdentifier(trim2, trim, str3);
    }

    public static String as(Object obj, String str) {
        try {
            return (String) XposedHelpers.getObjectField(obj, str.trim());
        } catch (NullPointerException | XposedHelpers.InvocationTargetError | NoSuchFieldError | NoSuchMethodError e) {
            e.printStackTrace();
            bi(e);
            bj();
            return null;
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:31:0x0087, code lost:
    
        if (r0.size() > 0) goto L24;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static String at(Object obj) {
        Object objectField;
        Object obj2;
        Object obj3;
        if (obj == null) {
            obj = y.by.getAweme();
        }
        if (obj == null) {
            return null;
        }
        Object objectField2 = XposedHelpers.getObjectField(obj, "video");
        if (objectField2 != null) {
            Object objectField3 = XposedHelpers.getObjectField(objectField2, "playAddr");
            if (objectField3 != null) {
                List list = (List) XposedHelpers.getObjectField(objectField3, "urlList");
                if (list.size() > 0) {
                    obj3 = list.get(0);
                    return (String) obj3;
                }
            }
            Object objectField4 = XposedHelpers.getObjectField(objectField2, "dashVideoInfo");
            Object objectField5 = XposedHelpers.getObjectField(objectField2, "h264PlayAddr");
            if (objectField5 != null || (objectField5 = XposedHelpers.getObjectField(objectField2, "playAddrH265")) != null) {
                List list2 = (List) XposedHelpers.getObjectField(objectField5, "urlList");
                if (list2.size() <= 0) {
                    if (objectField4 != null && (objectField = XposedHelpers.getObjectField(objectField4, "videoBitrates")) != null) {
                        List list3 = (List) objectField;
                        if (list3.size() > 0 && (obj2 = list3.get(0)) != null) {
                            list2 = (List) XposedHelpers.getObjectField(XposedHelpers.getObjectField(obj2, "playAddr"), "urlList");
                        }
                    }
                }
                obj3 = list2.get(0);
                return (String) obj3;
            }
        }
        obj3 = aa(obj, "getFirstPlayAddr");
        return (String) obj3;
    }

    public static String au(Object obj) {
        String cf = y.cf("DownFileName", "");
        if (cf == null) {
            return "PlusNE_" + System.currentTimeMillis();
        }
        if (TextUtils.isEmpty(cf)) {
            return "PlusNE_" + System.currentTimeMillis();
        }
        if (obj == null) {
            obj = y.by.getAweme();
        }
        if (obj == null) {
            return null;
        }
        String s = s(obj, cf);
        if (!TextUtils.isEmpty(s)) {
            return s.replaceAll("[^\\u4e00-\\u9fa5\\w\\-\\.]", "_");
        }
        return "PlusNE_" + System.currentTimeMillis();
    }

    public static String av(Object obj) {
        String as = as(obj, "desc");
        Object objectField = XposedHelpers.getObjectField(obj, "author");
        if (objectField == null) {
            return String.valueOf(System.currentTimeMillis());
        }
        return ("[" + as(objectField, "nickname") + "]_" + as).trim();
    }

    public static View aw(int i) {
        JsonHookStatic jsonHookStatic = y.by;
        if (jsonHookStatic.getActivity() == null || i == 0) {
            return null;
        }
        return jsonHookStatic.getActivity().findViewById(i);
    }

    public static View ax(int i, View view) {
        if (view == null || i == 0) {
            return null;
        }
        return view.findViewById(i);
    }

    public static void ay(String str, XC_MethodHook xC_MethodHook) {
        Class<?> ak;
        if (TextUtils.isEmpty(str) || (ak = ak(aj(str.trim()))) == null) {
            return;
        }
        XposedBridge.hookAllConstructors(ak, xC_MethodHook);
    }

    public static void az(Class<?> cls, String str, XC_MethodHook xC_MethodHook) {
        boolean z;
        String aj = aj(str.trim());
        if (aj == null) {
            bj();
            bi(b.i("CallAll失败:", aj, " 找不到此方法"));
            return;
        }
        Method[] declaredMethods = cls.getDeclaredMethods();
        if (declaredMethods.length == 0) {
            bj();
            bi(b.i("CallAll失败:", aj, " 没有方法列表"));
            return;
        }
        int length = declaredMethods.length;
        int i = 0;
        while (true) {
            if (i < length) {
                if (declaredMethods[i].getName().equals(aj)) {
                    z = true;
                    break;
                }
                i++;
            } else {
                z = false;
                break;
            }
        }
        if (!z) {
            return;
        }
        try {
            XposedBridge.hookAllMethods(cls, aj, xC_MethodHook);
        } catch (NoSuchMethodError e) {
            e.printStackTrace();
            bi(e);
            bj();
        }
    }

    public static void ba(String str, String str2, XC_MethodHook xC_MethodHook) {
        if (str == null) {
            bj();
            bi(b.i("CallAll失败:", str, " 找不到此类"));
            return;
        }
        String aj = aj(str.trim());
        if (aj == null) {
            bj();
            bi(b.i("CallAll失败:", aj, " 找不到此类1"));
            return;
        }
        if (str2 == null) {
            bj();
            bi(b.i("CallAll失败:", str2, " 找不到此方法"));
            return;
        }
        String aj2 = aj(str2.trim());
        if (aj2 == null) {
            bj();
            bi(b.i("CallAll失败:", aj2, " 找不到此方法"));
            return;
        }
        Class<?> ak = ak(aj);
        if (ak == null) {
            bi(b.i("CallAll失败:", aj, " 找不到此类2"));
        } else {
            az(ak, aj2, xC_MethodHook);
        }
    }

    public static void bb(MethodData methodData, XC_MethodHook xC_MethodHook) {
        ba(methodData.getClassName(), methodData.getMethodName(), xC_MethodHook);
    }

    public static void bc(String str, Object... objArr) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        try {
            XposedHelpers.findAndHookConstructor(str, y.by.getClassLoader(), objArr);
        } catch (XposedHelpers.InvocationTargetError | NoSuchFieldError | NoSuchMethodError | NullPointerException e) {
            e.printStackTrace();
            bi(e);
            bj();
        }
    }

    public static void bd(String str, String str2, Object... objArr) {
        if (TextUtils.isEmpty(str2) || TextUtils.isEmpty(str)) {
            return;
        }
        String aj = aj(str.trim());
        String aj2 = aj(str2.trim());
        for (int i = 0; i < objArr.length; i++) {
            Object obj = objArr[i];
            if (obj instanceof String) {
                Class<?> al = al((String) obj);
                if (al == null) {
                    bj();
                    bi("Hook失败:" + objArr[i] + " 找不到此类");
                    return;
                }
                objArr[i] = al;
            }
        }
        try {
            XposedHelpers.findAndHookMethod(aj, y.by.getClassLoader(), aj2, objArr);
        } catch (XposedHelpers.InvocationTargetError | NoSuchMethodError | NullPointerException e) {
            e.printStackTrace();
            bi(e);
            bj();
        }
    }

    public static void be(MethodData methodData, XC_MethodHook xC_MethodHook) {
        if (methodData == null) {
            return;
        }
        ClassDataList paramTypes = methodData.getParamTypes();
        if (paramTypes.isEmpty()) {
            bd(methodData.getClassName(), methodData.getMethodName(), xC_MethodHook);
            return;
        }
        ArrayList arrayList = new ArrayList();
        Iterator it = paramTypes.iterator();
        while (it.hasNext()) {
            arrayList.add(((ClassData) it.next()).getName());
        }
        arrayList.add(xC_MethodHook);
        bd(methodData.getClassName(), methodData.getMethodName(), arrayList.toArray());
    }

    public static void bf(Class<?> cls, String str, Object... objArr) {
        try {
            XposedHelpers.findAndHookMethod(cls, str, objArr);
        } catch (NullPointerException | XposedHelpers.InvocationTargetError | NoSuchMethodError e) {
            e.printStackTrace();
        }
    }

    public static boolean bg() {
        return b.h("allOpen", true);
    }

    public static void bh(Object obj) {
        bi(new Gson().toJson(obj));
    }

    public static void bi(Object... objArr) {
        StringBuilder sb = new StringBuilder();
        for (Object obj : objArr) {
            if (obj instanceof Exception) {
                Exception exc = (Exception) obj;
                StackTraceElement[] stackTrace = exc.getStackTrace();
                bi("---------------------");
                bi(exc.getMessage());
                for (int i = 0; i < stackTrace.length; i++) {
                    if (i >= 2) {
                        String className = stackTrace[i].getClassName();
                        if (!className.contains("android") && !className.startsWith("java") && !className.startsWith("dalvik")) {
                            bi(className + "." + stackTrace[i].getMethodName() + "():" + stackTrace[i].getLineNumber());
                        }
                    }
                }
            } else if (obj == null) {
                if (!TextUtils.isEmpty(sb)) {
                    sb.append(" , ");
                }
                sb.append("IS NULL");
            } else {
                if (!TextUtils.isEmpty(sb)) {
                    sb.append(" , ");
                }
                sb.append(obj);
            }
        }
        String sb2 = sb.toString();
        if (sb2 != null) {
            StringBuilder sb3 = new StringBuilder("[PN ");
            JsonHookStatic jsonHookStatic = y.by;
            sb3.append(jsonHookStatic.getAppName());
            sb3.append(" ");
            sb3.append(jsonHookStatic.getVersionName());
            sb3.append("]->");
            sb3.append(jsonHookStatic.getLpparam().packageName);
            sb3.append(" -> ");
            sb3.append((Object) sb2);
            XposedBridge.log(sb3.toString());
        }
    }

    public static void bj() {
        for (StackTraceElement stackTraceElement : Thread.currentThread().getStackTrace()) {
            String className = stackTraceElement.getClassName();
            if (!className.contains("android") && !className.startsWith("java") && !className.startsWith("dalvik")) {
                bi(className + "." + stackTraceElement.getMethodName() + "():" + stackTraceElement.getLineNumber());
            }
        }
    }

    public static Object bk(Class<?> cls, Object... objArr) {
        try {
            return XposedHelpers.newInstance(cls, objArr);
        } catch (NoSuchFieldError | NoSuchMethodError | NullPointerException | XposedHelpers.InvocationTargetError e) {
            bi(e);
            bj();
            e.printStackTrace();
            return null;
        }
    }

    public static Object bl(String str, Object... objArr) {
        try {
            return XposedHelpers.newInstance(ak(str), objArr);
        } catch (NoSuchFieldError | XposedHelpers.InvocationTargetError | NoSuchMethodError | NullPointerException e) {
            bi(e);
            bj();
            e.printStackTrace();
            return null;
        }
    }

    public static void bm(int i, View view) {
        float f;
        int i2;
        if (view != null) {
            if (!ae("View_ALL")) {
                view.setVisibility(View.VISIBLE);
                f = 1.0f;
            } else {
                if (i <= -1 || i >= 256) {
                    if (i == -1) {
                        i2 = 4;
                    } else if (i != -2) {
                        return;
                    } else {
                        i2 = 8;
                    }
                    view.setVisibility(i2);
                    return;
                }
                view.setVisibility(View.VISIBLE);
                f = i / 255.0f;
            }
            view.setAlpha(f);
        }
    }

    public static void bn(Object obj, String str, String str2) {
        try {
            XposedHelpers.setObjectField(obj, str, str2);
        } catch (XposedHelpers.InvocationTargetError | NoSuchFieldError | NoSuchMethodError | NullPointerException e) {
            bi(e);
            bj();
            e.printStackTrace();
        }
    }

    public static void q(int i) {
        ab(y.by.getHook_ViewPager(), c.t(MethodMatcher.create().declaredClass("com.ss.android.ugc.aweme.common.widget.VerticalViewPager").paramTypes(new String[]{"int", "boolean"}).returnType("void")).getMethodName(), Integer.valueOf(i), Boolean.TRUE);
    }

    public static synchronized void r(Object obj) {
        synchronized (j.class) {
            JsonHookStatic jsonHookStatic = y.by;
            if (jsonHookStatic.getDy().getDisLikeAweme() != null) {
                ad(ak(jsonHookStatic.getDy().getDisLikeAweme().getClassName()), jsonHookStatic.getDy().getDisLikeAweme().getMethodName(), obj, null, "homepage_hot", "long_press", Boolean.FALSE, null, 34, null);
                f i = f.i();
                i.n();
                i.l("已反馈不喜欢该视频");
            }
        }
    }

    public static String s(Object obj, String str) {
        if (str == null) {
            return str;
        }
        if (obj == null) {
            obj = y.by.getAweme();
        }
        if (obj == null) {
            return null;
        }
        Object objectField = XposedHelpers.getObjectField(obj, "author");
        if (objectField != null) {
            String as = as(objectField, "nickname");
            if (!TextUtils.isEmpty(as)) {
                str = str.replace("{author}", as).replace("#author#", as);
            }
        }
        String as2 = as(obj, "desc");
        if (!TextUtils.isEmpty(as2)) {
            str = str.replace("{desc}", as2).replace("#desc#", as2);
        }
        String replace = str.replace("{time}", g.n()).replace("#time#", g.n());
        String as3 = as(obj, "aid");
        return !TextUtils.isEmpty(as3) ? replace.replace("{id}", as3).replace("#id#", as3) : replace;
    }

    public static synchronized void t(Object obj, String str) {
        synchronized (j.class) {
            new Thread((Runnable) new af(as(obj, "aid"), str, obj, 2)).start();
        }
    }

    public static synchronized void u(Object obj, boolean z) {
        synchronized (j.class) {
            new Thread((Runnable) new h(obj, z, 0)).start();
        }
    }

    public static synchronized void v(Object obj, boolean z) {
        synchronized (j.class) {
            new Thread((Runnable) new h(obj, z, 1)).start();
        }
    }

    public static Object w(XC_MethodHook.MethodHookParam methodHookParam) {
        try {
            return XposedBridge.invokeOriginalMethod(methodHookParam.method, methodHookParam.thisObject, methodHookParam.args);
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
            bi(e);
            bj();
            return null;
        }
    }

    public static Object x(String str, int i, int i2) {
        try {
            return XposedHelpers.newInstance(ak("cn.soulapp.android.square.ui.PopupMenu.b"), new Object[]{str, Integer.valueOf(i2), Integer.valueOf(i)});
        } catch (Throwable th) {
            th.printStackTrace();
            return XposedHelpers.newInstance(ak("cn.soulapp.android.square.ui.PopupMenu.c"), new Object[]{str, Integer.valueOf(i2), Integer.valueOf(i)});
        }
    }

    public static Object y(Resources resources) {
        AssetManager assets = resources.getAssets();
        try {
            Method declaredMethod = assets.getClass().getDeclaredMethod("addAssetPath", String.class);
            declaredMethod.setAccessible(true);
            return declaredMethod.invoke(assets, y.by.getModulePath());
        } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
            XposedBridge.log("[PlusNE]->添加宿主资源失败:" + e.getMessage());
            e.printStackTrace();
            return null;
        }
    }

    public static void z(Context context) {
        if (context == null) {
            return;
        }
        for (int i = 0; i < 5; i++) {
            Object y = y(context.getResources());
            if ((y != null ? ((Integer) y).intValue() : 0) > 0) {
                return;
            }
        }
    }
}
